Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XFuBluetoothNetwork.h

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * X-Forge Engine <br>
00004  * Copyright 2000-2003 Fathammer Ltd
00005  *
00006  * \brief Default implementation for a Bluetooth communication manager.
00007  *
00008  * $Id: XFuBluetoothNetwork.h,v 1.1 2003/08/01 07:41:23 lars Exp $
00009  * $Date: 2003/08/01 07:41:23 $
00010  * $Revision: 1.1 $
00011  */
00012 
00013 #ifndef XFUBLUETOOTHNETWORK_H_INCLUDED
00014 #define XFUBLUETOOTHNETWORK_H_INCLUDED
00015 
00016 #include <xfcore/net/XFcUnknownSender.h>
00017 #include <xfcore/net/XFcClientLost.h>
00018 #include <xfcore/net/socket/XFcAddress.h>
00019 #include <xfcore/net/XFcCommunicationConstants.h>
00020 #include <xfcore/net/XFcDeviceDiscovery.h>
00021 
00022 #include <xfutil/XFuDynamicArray.h>
00023 
00024 
00025 class XFuSerializable;
00026 class XFcCommunicationScheduler;
00027 class XFcUnknownSender;
00028 class XFcClientLost;
00029 class XFcDataReceiver;
00030 class XFcObjectDataFrame;
00031 class XFcBtCommService;
00032 class XFcHostEntry;
00033 class XFcBtHostResolver;
00034 class XFcAdvertiser;
00035 class XFcBtClientWin;
00036 class XFcBtServerSearch;
00037 class XFcBtAddress;
00038 class XFcBtHandler;
00039 
00040 
00041 class XFuBluetoothNetwork : public XFuNetwork,
00042                                       public XFcUnknownSender,
00043                                       public XFcClientLost,
00044                                       public XFcDeviceDiscovery
00045 {
00046 private:
00047 
00048     //! Pointer to array of communication event handlers.
00049     XFuDynamicArray<XFuNetworkEventHandler*> *mNetworkEventHandlers;
00050 
00051     //! Pointer to the communication scheduler.
00052     XFcCommunicationScheduler *mCommunicationScheduler;
00053 
00054     //! Pointer to the communication handler.
00055     XFcBtHandler *mCommunicationHandler;
00056 
00057     //! Holds pointer to the Bluetooth communication services.
00058     XFcBtCommService *mCommunicationService;
00059 
00060     //! Pointer to the default data receiver.
00061     XFcDataReceiver *mDefaultDataReceiver;
00062 
00063     //! Holds pointer to bt server search.
00064     XFcBtServerSearch *mBtServerSearch;
00065 
00066     //! Holds bluetooth communication service, needed for bluetooth SDP and first free server port query.
00067     XFcBtCommService *mService;
00068 
00069     //! Holds pointer to bt host resolver.
00070     XFcBtHostResolver *mHostResolver;
00071 
00072     //! Id of the communication handler.
00073     INT32 mCommunicationHandlerId;
00074 
00075     //! Array of pointers to clients.
00076     XFcBtClientWin *mClient;
00077 
00078     //! Holds ClientId, only one client is supported for now. 
00079     INT32 mClientId;
00080 
00081     //! Game token that is checked before new clients are allowed to connect.
00082     UINT32 mAcceptGameToken;
00083 
00084     //! Holds game port.
00085     UINT16 mGamePort;
00086 
00087 protected:
00088 
00089     //! Deletes all clients.
00090     virtual void deleteAllClients();
00091 
00092     //! Protected constructor.
00093     XFuBluetoothNetwork();
00094 
00095     //! Initializes this Bluetooth communication manager.
00096     INT init();
00097 
00098     //! Initializes enable service.
00099     INT initEnable(UINT16 aPort, INT aIsServer);
00100 
00101 public:
00102 
00103     //! Static constructor.
00104     static XFuBluetoothNetwork * create();
00105 
00106     //! Enables the Bluetooth communication handler and opens it for service.
00107     virtual INT enableClientService();
00108 
00109     //! Enables the Bluetooth communication handler and opens it for service.
00110     virtual INT enableServerService(UINT16 aPort);
00111 
00112     //! Closes the currently active service (communication handler).
00113     virtual void closeService();
00114 
00115     //! Resets the communication manager.
00116     virtual void reset();
00117 
00118     //! Runs the communication scheduler.
00119     virtual void runCommunicationScheduler();
00120 
00121     //! Connection lost handler (XFuClientLost) (callback).
00122     virtual void clientLost(INT32 aClientId);
00123 
00124     //! Adds a client with the specific address.
00125     /*! \return The client id or XFCNET_CLIENTADD_ERROR if failed.
00126      */
00127     virtual INT32 addClient(XFcAddress *aAddress, INT32 aTimeoutTime = 15000);
00128 
00129     //! Returns the specified client.
00130     virtual XFcClientCommWin * getClient(INT32 aClientId);
00131 
00132     //! Removes the specified client.
00133     virtual void removeClient(INT32 aClientId);
00134 
00135     //! Removes all clients.
00136     virtual void removeAllClients();
00137 
00138     //! Returns the game token that is checked before new clients are allowed to connect.
00139     virtual UINT32 getAcceptGameToken();
00140 
00141     //! Sets the game token that is checked before new clients are allowed to connect.
00142     virtual void setAcceptGameToken(UINT32 aAcceptGameToken);
00143 
00144     //! Sends a game connection packet.
00145     virtual void sendGameConnectPacket(INT32 aClientId, UINT32 aGameToken);
00146 
00147     //! Returns a pointer to the default data receiver.
00148     virtual XFcDataReceiver * getDefaultDataReceiver();
00149 
00150     //! Returns the specified data receiver.
00151     virtual XFcDataReceiver * getDataReceiver(UINT32 aId);
00152 
00153     //! Adds a new data receiver.
00154     virtual INT addDataReceiver(UINT32 aId, XFcDataReceiver *aReceiver);
00155 
00156     //! Sets the default data receiver.
00157     virtual void setDefaultDataReceiver(XFcDataReceiver *aReceiver);
00158 
00159     //! Removes a data receiver.
00160     virtual XFcDataReceiver * removeDataReceiver(UINT32 aId);
00161 
00162      //! Handle data from an unknown client (callback).
00163     virtual INT handleSender(const void *aAddress, const CHAR8 *aData, INT32 aLen);
00164 
00165     //! Get packet frame.
00166     virtual XFcObjectDataFrame * getPacketFrame(INT32 aClientId, XFCNET_MESSAGE_SLOT aSlot);
00167 
00168     //! Get recent state frame.
00169     virtual XFcObjectDataFrame * getRecentStateFrame(INT32 aClientId, INT32 aRecentId);
00170 
00171     //! Remove recent state frame.
00172     virtual void removeRecentStateFrame(INT32 aClientId, INT32 aRecentId);
00173 
00174     //! Returns the round trip time for the specified client.
00175     virtual INT32 getRoundTripTime(INT32 aClientId);
00176 
00177     //! Sends a serializable object to the specified client.
00178     virtual INT32 send(INT32 aClientId, UINT32 aReceiverId, XFCNET_MESSAGE_SLOT aSlot, XFuSerializable *aSerializable);
00179 
00180     //! Sends a serializable object to the specified client as a recent state packet.
00181     virtual INT32 sendRecentState(INT32 aClientId, UINT32 aReceiverId, INT32 aRecentId, XFuSerializable *aSerializable);
00182 
00183     //! Adds a communication event handler.
00184     virtual void addEventHandler(XFuNetworkEventHandler *aHandler);
00185 
00186     //! Removes a communication event handler.
00187     virtual void removeEventHandler(XFuNetworkEventHandler *aHandler);
00188 
00189     //! Removes all communication event handlers.
00190     virtual void removeAllEventHandlers();
00191 
00192     //! Stops device discovery.
00193     virtual void stopDeviceDiscovery();
00194 
00195     //! Stops server discovery.
00196     virtual void stopServerDiscovery();
00197 
00198     //! Stops server advertiser.
00199     virtual void stopAdvertiser();
00200 
00201     //! Starts device discovery.
00202     virtual INT startDeviceDiscovery();
00203 
00204     //! Starts server discovery, if address is NULL engine will search througth all available bt devices.
00205     virtual INT startServerDiscovery(const XFcBtAddress *aAddress);
00206 
00207     //! Starts advertiser, if message is NULL default message is used.
00208     virtual INT startAdvertiser(const CHAR8 *aMessage);
00209 
00210     //! Callback for device discovery.
00211     virtual void deviceDiscovery(const XFcLinkedList<XFcHostEntry *> &aHostEntry);
00212     //! Callback for server discovery.
00213     virtual void deviceDiscovery(const XFcLinkedList<XFcAdvertiser *> &aAdvertiser);
00214 
00215     //! Virtual destructor. Closes all open tasks and deletes all created objects.
00216     virtual ~XFuBluetoothNetwork();
00217 
00218 };
00219 
00220 
00221 #endif // !XFUBLUETOOTHNETWORK_H_INCLUDED

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch